<template>
    <div @mouseleave="show=false" class="dropdown">
        <div @click="show=true" class="js-dropdown">{{selected.name || "车龄"}}</div>
        <div v-if="show" class="menu">
            <div @click="select(item) " v-for="item in cheling" class="item">{{item.name}}</div>
        </div>
    </div>
</template>

<script>
    export default {
        props: ['cheling', 'onSelect'],
        data() {
            return {
                show: false,
                selected: {},
            }
        },
        methods: {
            select: function (item) {
                this.selected = item;
                if (this.onSelect) {
                    this.onSelect(item);
                }
            }
        }
    }

</script>

<style scoped>
    .dropdown {
        display: inline-block;
        margin-right: 5px;
    }

    .js-dropdown {
        padding: 2px 5px;
        position: relative;
    }

    .menu>* {
        display: block;
    }

    .menu {
        position: absolute;
        background-color: white;
    }

    .js-dropdown,
    .menu {
        width: 70px;
        border: 1px solid rgba(0, 0, 0, 0.1)
    }

    .item {
        margin-bottom: 5px;
        margin-bottom: 10px;

    }
</style>